//
//  HomeListCell.m
//  FoodCorner
//
//  Created by Summer on 16/2/28.
//  Copyright © 2016年 zhangchao. All rights reserved.
//

#import "HomeListCell.h"
#import <SDAutoLayout/UIView+SDAutoLayout.h>
#import "MainListModel.h"
#import "CategoryModel.h"
#import <SDWebImage/UIImageView+WebCache.h>
#define rgba(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
@implementation HomeListCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllViews];
    }
    return self;
}
- (void)addAllViews
{
    CGFloat margin = 10;
    self.imgIcon = [UIImageView new];
    _imgIcon.layer.masksToBounds = YES;
    _imgIcon.layer.cornerRadius = 165.0 / 2;
    [self.contentView addSubview:self.imgIcon];
    
    self.lblTitle = [UILabel new];
    self.lblTitle.font = [UIFont systemFontOfSize:15];
    self.lblTitle.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:self.lblTitle];
    
    self.lblSubtitle = [UILabel new];
    _lblSubtitle.numberOfLines = 0;
    self.lblSubtitle.textColor = [UIColor grayColor];
    self.lblSubtitle.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.lblSubtitle];
    
    self.lineView = [UIView new];
    self.lineView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.lineView];
    
    self.imgIcon.sd_layout
    .leftSpaceToView(self.contentView,margin)
    .topSpaceToView(self.contentView,margin)
    .widthIs(165)
    .heightIs(165);
    
    self.lblTitle.sd_layout
    .leftSpaceToView(self.imgIcon ,margin)
    .topSpaceToView(self.contentView,margin - 3)
    .rightSpaceToView(self.contentView,margin)
    .heightIs(20);
    
    self.lblSubtitle.sd_layout
    .topSpaceToView(self.lblTitle,margin / 2)
    .leftSpaceToView(self.imgIcon,margin)
    .rightSpaceToView(self.contentView,margin)
    .autoHeightRatio(0);
    
    self.lineView.sd_layout
    .topSpaceToView(self.imgIcon,margin)
    .rightSpaceToView(self.contentView,0)
    .leftSpaceToView(self.contentView,0)
    .heightIs(1);
    
    [self setupAutoHeightWithBottomView:self.lineView bottomMargin:0];

}
-(void)setModel:(MainListModel *)model
{
        //_model = model;
        self.lblTitle.text = model.title;
        self.lblSubtitle.text = model.tags;
        [self.imgIcon sd_setImageWithURL:[NSURL URLWithString:[model.albums lastObject]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
}
-(void)setCategoryModel:(CategoryModel *)categoryModel
{
    self.lblTitle.text = categoryModel.title;
    self.lblSubtitle.text = categoryModel.tags;
    [self.imgIcon sd_setImageWithURL:[NSURL URLWithString:[categoryModel.albums lastObject]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
